<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

	<h:form id="createCarForm">
	
		<p:messages id="ccmessages" for="fileup" showDetail="false" closable="true" globalOnly="true"/>
	
	<p:panelGrid id="panelGrid">
		<p:row>
		<p:column><h:outputText value="Manufacturer: " /></p:column>
		<p:column>
			<p:selectOneMenu id="manufacturer-select" value="#{createCarBean.manufacturer}" valueChangeListener="#{createCarBean.manufactureChange}" 
											  converter="javax.faces.Long" validatorMessage="Required field">
								<f:selectItems value="#{createCarBean.manufactures}"/>
								<p:ajax event="change" update=":createCarForm"/>
								<f:validateDoubleRange minimum="1"></f:validateDoubleRange>
			</p:selectOneMenu>
			<p:message for="manufacturer-select" display="text"/>
		</p:column>
		</p:row>
		<p:row>
		<p:column><h:outputText value="Model: " /></p:column>
		<p:column>
			<p:selectOneMenu id="model-select" value="#{createCarBean.model}"
											  converter="javax.faces.Long" validatorMessage="Required field">
								<f:selectItems value="#{createCarBean.models}"/>
								<f:validateDoubleRange minimum="1"></f:validateDoubleRange>
			</p:selectOneMenu>
			<p:message for="model-select" display="text"/>
		</p:column>
		</p:row>
		<p:row>
			<p:column><h:outputText value="Description: " /></p:column>
			<p:column>
				<p:inputTextarea id="productDescription" rows="10" value="#{createCarBean.advertising.carDescription}" styleClass="input-width"/>  
			</p:column>
		</p:row>
		<p:row>
			<p:column><h:outputText value="Price: " /></p:column>
			<p:column>
				<p:inputText id="price-field" required="true" value="#{createCarBean.advertising.price}" 
							 requiredMessage="Required field" validatorMessage="Need to be less then 0" styleClass="input-width">
					<f:convertNumber pattern="#0"/>
					<f:validateDoubleRange minimum="0"/>
				</p:inputText>
				<p:message for="price-field" display="text"/>
			</p:column>
		</p:row>
		<p:row>
			<p:column><h:outputText value="Location: " /></p:column>
			<p:column>
				<p:inputText id="location-field" value="#{createCarBean.advertising.location}" 
							  styleClass="input-width">
				</p:inputText>
			</p:column>
		</p:row>
		<p:row rendered="false">
			<p:column colspan="2">
				<p:galleria value="#{createCarBean.carPictures}" var="image" panelWidth="500" panelHeight="313" showCaption="true">  
				    <p:graphicImage value="#{createCarBean.getPath(image)}" alt="" title=""/>  
				</p:galleria>  
	        </p:column>
        </p:row>
		<p:row rendered="#{!createCarBean.isEdit()}">
			<p:column colspan="2">
				<p:fileUpload id="fileup" fileUploadListener="#{createCarBean.handleFileUpload}"  
					            mode="advanced"   
					            update="ccmessages"
					            allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>    
			</p:column>
		</p:row>
	    <p:row>
	    	<p:column colspan="2">
				<p:commandButton value="Save" update="panelGrid,:cars-form" actionListener="#{createCarBean.save}"/>
				<p:commandButton value="Cancle" type="button" onclick="createDlg.hide()" />
			</p:column>
     	</p:row> 
	</p:panelGrid>
	
	</h:form>

</ui:composition>